package top.cluski.shardingsphere;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import top.cluski.shardingsphere.entity.Dict;
import top.cluski.shardingsphere.entity.User;
import top.cluski.shardingsphere.mapper.DictMapper;
import top.cluski.shardingsphere.mapper.UserMapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * 绑定表测试
 */
@SpringBootTest
public class ShardingJDBCTestBind {

    @Resource
    DictMapper dictMapper;

    @Resource
    UserMapper userMapper;

    @Test
    public void testDictSharding() {
        Dict d = new Dict();
//        d.setDictId((long) 1);
        d.setUstatus("1");
        d.setUvalue("正常");
        dictMapper.insert(d);

        Dict d2 = new Dict();
//        d2.setDictId((long) 2);
        d2.setUstatus("0");
        d2.setUvalue("不正常");
        dictMapper.insert(d2);

        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setUserName("User No" + i);
            user.setUstatus(String.valueOf(i % 2));
            user.setUage(i * 10);
            userMapper.insert(user);
        }
    }

    @Test
    public void queryUserStatus() {
        List<User> users = userMapper.queryUserStatus();
        users.forEach(System.out::println);
    }
}
